//
//  SNewsMyTableViewCell.m
//  News
//
//  Created by dlios on 15-5-14.
//  Copyright (c) 2015年 PEAK. All rights reserved.
//

#import "SNewsMyTableViewCell.h"

@implementation SNewsMyTableViewCell

-(void)dealloc
{
    [_cellImageView release];
    [_cellLabelOne release];
    [_cellLabelTwo release];
    [_modelThree release];
    [super dealloc];
    
}

- (void)awakeFromNib {
    // Initialization code
    
    
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.cellImageView = [[UIImageView alloc] init];
//        _cellImageView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_cellImageView];
        [_cellImageView release];
        
        self.cellLabelOne = [[UILabel alloc] init];
        _cellLabelOne.backgroundColor = [UIColor whiteColor];
        _cellLabelOne.numberOfLines = 0;
        _cellLabelOne.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:_cellLabelOne];
        [_cellLabelOne release];
        
        self.cellLabelTwo = [[UILabel alloc] init];
        _cellLabelTwo.textAlignment = NSTextAlignmentLeft;
        _cellLabelTwo.backgroundColor = [UIColor whiteColor];
        _cellLabelTwo.numberOfLines = 0;
        [self.contentView addSubview:_cellLabelTwo];
        [_cellLabelTwo release];
        
    }
    
    return self;
    
}


-(void)layoutSubviews
{

    
    [super layoutSubviews];

    
    _cellImageView.frame = CGRectMake(0, 5, self.contentView.frame.size.width / 3.1, self.contentView.frame.size.height - 5);
    
    _cellLabelOne.frame = CGRectMake(_cellImageView.frame.size.width + 10, 10, self.contentView.frame.size.width -  _cellImageView.frame.size.width - 10, 22);
    
    _cellLabelTwo.frame = CGRectMake(_cellImageView.frame.size.width + 10, _cellLabelOne.frame.size.height + 22, self.contentView.frame.size.width -  _cellImageView.frame.size.width - 10, 50);
    
    
}

-(void)setModelThree:(SNwesThree *)modelThree
{
    if (modelThree != _modelThree) {
        [_modelThree release];
        _modelThree = [modelThree retain];
        
    }
    NSURL * url = [NSURL URLWithString:modelThree.imgsrc];
    
    [_cellImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"``_3(NZ4U{L@4L7FN0J70DA"]];
    
    _cellLabelOne.text = modelThree.title;
    _cellLabelTwo.text = modelThree.digest;
    
 
}

+(CGFloat)heightWithText:(NSString*)text
{
    //    设置一个字典保存文本属性

    NSDictionary *dic1 = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    
    //    预设一个尺寸 文本最大不会超过这个尺寸
    CGSize size = CGSizeMake(375, 1000);

    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic1 context:nil];

    //    返回得到的高度
    return rect.size.height;
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
